import axios from 'axios';
import { getToken, getTokenType } from '@/utils/auth';
import { Toast } from 'vant';

const service = axios.create({
  withCredentials: true,
  timeout: 50000
})

// 请求拦截
service.interceptors.request.use(
  config => {
    config.headers['Authorization'] = getTokenType() + ' ' + getToken();
    //config.baseURL = process.env.NODE_ENV === 'development' ? process.env.VUE_APP_BASE_API_TEST : localStorage.getItem('baseUrl') + '/factory/v1/jy-api';
    config.baseURL = process.env.NODE_ENV === 'development' ? process.env.VUE_APP_BASE_API_TEST : localStorage.getItem('baseUrl') + '/factory/v1/';
    if(process.env.NODE_ENV === 'development'){
      config.headers['x-request-wan-access'] = true;
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
)

// 响应拦截
service.interceptors.response.use(
  response => {
    return response.data;
  },
  error => {
    return Promise.reject(error);
  }
)

export default service;
